package org.cable.link.controller;


import org.cable.common.util.JsonData;
import org.cable.link.controller.request.ShortLinkAddRequest;
import org.cable.link.controller.request.ShortLinkDelRequest;
import org.cable.link.controller.request.ShortLinkPageRequest;
import org.cable.link.controller.request.ShortLinkUpdateRequest;
import org.cable.link.service.ShortLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 二当家小D
 * @since 2021-12-09
 */
@RestController
@RequestMapping("/api/link/v1")
public class ShortLinkController {


     @Autowired
     private ShortLinkService shortLinkService;


    @PostMapping("/add")
    public JsonData createShortLink(@RequestBody ShortLinkAddRequest request){

        JsonData jsonData = shortLinkService.createShortLink(request);

        return jsonData;
    }

    /**
     * 分页查找短链
     */
    @GetMapping("page")
    public JsonData pageByGroupId(@RequestBody ShortLinkPageRequest shortLinkPageRequest){


      Map<String,Object> result =  shortLinkService.pageByGroupId(shortLinkPageRequest);

      return JsonData.buildSuccess(result);

    }

    /**
     * 删除操作
     */
    @PostMapping("del")
    public JsonData del(@RequestBody ShortLinkDelRequest request){
        JsonData jsonData =  shortLinkService.del(request);
        return jsonData;
    }

    /**
     * 更新操作
     */
    @PostMapping("update")
    public JsonData del(@RequestBody ShortLinkUpdateRequest request){
        JsonData jsonData =  shortLinkService.updateShortLink(request);
        return jsonData;
    }


}

